package com.hyy.service.serviceImpl;

import com.hyy.bean.Merchandise;
import com.hyy.dao.MerchandiseDao;
import com.hyy.dao.daoImpl.MerchandiseDaoImpl;
import com.hyy.service.MerchandiseService;

import java.sql.SQLException;
import java.util.List;

public class MerchandiseServiceImpl implements MerchandiseService {

	MerchandiseDao merchandiseDao = new MerchandiseDaoImpl();


	//显示所有商品
	@Override
	public List<Merchandise> showAllProducts() {

		try {
			return merchandiseDao.findAllProducts();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public List<Merchandise> findProductByKeyword(String keyword) {

		try {
			return merchandiseDao.findProductByKeyword(keyword);
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return null;
	}

	@Override
	public Merchandise findProductByID(Long id) {
		try {
			return merchandiseDao.findProductById(id);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public boolean outProductById(Long id, Long num) {

		try {
			return merchandiseDao.outProductById(id,num);
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return false;
	}

	@Override
	public boolean updateProduct(Merchandise merchandise) {
		try {
			return merchandiseDao.updateProduct(merchandise);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean deletProductById(Long mid) {
		try {
			return merchandiseDao.deleteProduct(mid);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean addNewProduct(Merchandise merchandise) {
		try {
			return merchandiseDao.addProduct(merchandise);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
}
